package org.hawk.gwt.ppc.introspection;

import java.util.List;

import org.hawk.gwt.ppc.parser.Token;

/**
 * Represents scope of variable life.
 * This could be either method or code block or whole 
 * class with fields as variables.
 *  
 * @author alex.bereznevatiy@gmail.com
 *
 */
public interface JavaScope extends JavaStatement {
	
	/**
	 * @param marker
	 * @return java scope (this one or its child) in case of token belongs to this scope or <code>null</code>
	 * if this scope is not contain this scope.
	 */
	JavaScope getScope(Token marker);
	
	/**
	 * @param line
	 * @param offset
	 * @return scope for line and offset in source file.
	 */
	JavaScope getScope(int line, int offset);
	
	/**
	 * @param name
	 * @param marker
	 * @return java variable that is declared on the token position or <code>null</code> in case there is no
	 * variable declared in this scope or parents. 
	 */
	JavaVariable getVariable(String name, Token marker);
	
	/**
	 * @param name
	 * @param line
	 * @param offset
	 * @return java variable that is declared on the token position or <code>null</code> in case there is no
	 * variable declared in this scope or parents. 
	 */
	JavaVariable getVariable(String name, int line, int offset);
	
	/**
	 * @return parent scope (or <code>null</code> if it is top-level scope)
	 */
	JavaScope getParent();
	
	/**
	 * @return children scopes of this one.
	 */
	List<JavaScope> getChildren();
	
	/**
	 * Searches for method with signature passed. If search fails - delegate search to the parent scope.
	 * If there is no parent scope - should return <code>null</code>. If this scope is {@link JavaTypeScope}
	 * it should also search supertypes.
	 * @param name
	 * @param arguments types
	 * @return method that best matches the name and parameters passed or <code>null</code>
	 * if there is no matching method.
	 */
	JavaMethod getBestMatchMethod(String name, List<JavaTypeScope> arguments);
}
